package l1cache

type mstatDayStat struct {
	statBase
	stat *MstatDayValue
}

func newMstatDayStat() *mstatDayStat {
	return &mstatDayStat{
		statBase: newStatBase(),
		stat:     NewMstatDayValue(),
	}
}

func (_this *mstatDayStat) GetField() map[string]int64 {
	values := getAllField(*_this.stat)
	return values
}

func (_this *mstatDayStat) Incr_Wtimes() int32 {
	_this.Lock() //结构体自己的锁，可以防止重入锁
	defer _this.Unlock()
	_this.stat.Wtimes++
	return _this.stat.Wtimes
}

//总输局数量
func (_this *mstatDayStat) Incr_Ltimes() int64 {
	_this.Lock() //结构体自己的锁，可以防止重入锁
	defer _this.Unlock()
	_this.stat.Ltimes++
	return _this.stat.Ltimes
}

//在玩时长
func (_this *mstatDayStat) Incr_PlayTime(playTime int64) int64 {
	_this.Lock() //结构体自己的锁，可以防止重入锁
	defer _this.Unlock()
	_this.stat.Playtime += playTime
	return _this.stat.Playtime
}

//玩法赢牌次数
func (_this *mstatDayStat) Incr_Playwtimes(gameid int32) int32 {
	_this.Lock() //结构体自己的锁，可以防止重入锁
	defer _this.Unlock()
	var incr int32
	switch gameid {
	case 1000:
		_this.stat.Wtimes_1000++
		incr = _this.stat.Wtimes_1000
	case 1001:
		_this.stat.Wtimes_1001++
		incr = _this.stat.Wtimes_1001
	case 1002:
		_this.stat.Wtimes_1002++
		incr = _this.stat.Wtimes_1002
	case 1003:
		_this.stat.Wtimes_1003++
		incr = _this.stat.Wtimes_1003
	case 1004:
		_this.stat.Wtimes_1004++
		incr = _this.stat.Wtimes_1004
	case 1009:
		_this.stat.Wtimes_1009++
		incr = _this.stat.Wtimes_1009
	case 1022:
		_this.stat.Wtimes_1022++
		incr = _this.stat.Wtimes_1022
	case 1037:
		_this.stat.Wtimes_1037++
		incr = _this.stat.Wtimes_1037
	}
	return incr
}

//玩法输牌次数
func (_this *mstatDayStat) Incr_Playltimes(gameid int32) int32 {
	_this.Lock() //结构体自己的锁，可以防止重入锁
	defer _this.Unlock()
	var incr int32
	switch gameid {
	case 1000:
		_this.stat.Ltimes_1000++
		incr = _this.stat.Ltimes_1000
	case 1001:
		_this.stat.Ltimes_1001++
		incr = _this.stat.Ltimes_1001
	case 1002:
		_this.stat.Ltimes_1002++
		incr = _this.stat.Ltimes_1002
	case 1003:
		_this.stat.Ltimes_1003++
		incr = _this.stat.Ltimes_1003
	case 1004:
		_this.stat.Ltimes_1004++
		incr = _this.stat.Ltimes_1004
	case 1009:
		_this.stat.Ltimes_1009++
		incr = _this.stat.Ltimes_1009
	case 1022:
		_this.stat.Ltimes_1022++
		incr = _this.stat.Ltimes_1022
	case 1037:
		_this.stat.Ltimes_1037++
		incr = _this.stat.Ltimes_1037
	}
	return incr
}

func (_this *mstatDayStat) Reset() (result map[string]int64) {
	_this.Lock()
	defer _this.Unlock()
	result = _this.GetField()
	_this.stat = nil
	_this.stat = NewMstatDayValue()
	_this.setActiveTime()
	return
}

func (_this *mstatDayStat) CheckLru() bool {
	_this.RLock()
	defer _this.RUnlock()
	if _this.checkActive() {
		if _this.stat.IsEmpty() {
			return true
		}
	}
	return false
}
